﻿using System;
using System.Collections.Generic;
using Color = System.Drawing.Color;
using SwinGame;

namespace Gundam_2._0_Alpha.src
{
    public class Circles: DestroyableObject
    {
        private float xPos, yPos, pathRadius,degreesInc, degrees = 0, xMove,yMove;
        private bool isAnimated, isActive, isRandom, isPlayer;
        private int damage;
        private Character c;

        public int Damage
        {
            get { return damage; }
            set { damage = value; }
        }

        public bool IsActive
        {
            get { return isActive; }
            set { isActive = value; }
        }

        public float PathRadius
        {
            get { return pathRadius; }
            set { pathRadius = value; }
        }

        public float Degrees
        {
            get { return degrees; }
            set { degrees = value; }
        }

        public Circles(string name,Sprite circle,int health, float radius,float degrees, float degreesInc, int xPos, int yPos,bool isAnimated,bool isRandom, Character c, bool isPlayer)
            :base(name,health, circle)
        {
            this.isPlayer = isPlayer;
            this.pathRadius = radius;
            this.degreesInc = degreesInc;
            this.degrees = degrees;
            this.isAnimated = isAnimated;
            this.c = c;
            isActive = false;
            this.isRandom = isRandom;
            xMove = xPos;
            yMove = yPos;
            if (isRandom)
            {
                objectSprite.X = xPos;
                objectSprite.Y = yPos;
            }
            else
            {
                objectSprite.X = xPos;
                objectSprite.Y = yPos;
            }
            
        }

        public override void Draw()
        {
            if (isActive)
            {
                objectSprite.Draw();
                if (isAnimated)
                    objectSprite.UpdateAnimation();
            }
        }

        public override void Update(GameController gc)
        {
            xPos = pathRadius * (float)System.Math.Cos(degrees);
            yPos = pathRadius * (float)System.Math.Sin(degrees);

            if (isRandom)
            {
                objectSprite.X = xPos + xMove;
                objectSprite.Y = yPos + yMove;
            }
            else
            {
                objectSprite.X = xPos + c.ObjectSprite.X + c.ObjectSprite.Width / 4;
                objectSprite.Y = yPos + c.ObjectSprite.Y + c.ObjectSprite.Height / 4;
            }

            degrees += degreesInc;

            if (!isAnimated)
                GlobalConst.DmgCheck.CheckDamage(gc.GameStages.Peek().CharList, this, isPlayer, damage, gc, false, 0);
            else if (isAnimated && objectSprite.CurrentCell > 2)
                GlobalConst.DmgCheck.CheckDamage(gc.GameStages.Peek().CharList, this, isPlayer, damage, gc, false, 0);
        }
    }
}
